import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'productGroupDefinitionM',

  state: {
    data: {},
    transFormData: [],
    rowData: [],
    conditionData: [],
  },

  effects: {
    //查询
    *getData({ payload, callback }, { call, put }) {
      const res = yield call(api.getProductData, payload);
      if (res.code == 0) {
        yield put({
          type: 'save',
          payload: {
            data: res.data,
          },
        });
        callback(res.data);
      } else {
        message.error('查询失败');
      }
    },

    //删除
    *deleteData({ payload, callback }, { call, put }) {
      const res = yield call(api.productGroupDefinition.deleteData, payload);
      return res;
    },

    //修改
    *editData({ payload, callback }, { call, put }) {
      const res = yield call(api.productGroupDefinition.editData, payload);
      return res;
    },

    //新增
    *addData({ payload, callback }, { call, put }) {
      const res = yield call(api.productGroupDefinition.addData, payload);
      return res;
    },

    //获取机构信息
    *getCondition({ payload, callback }, { call, put }) {
      const res = yield call(api.productGroupDefinition.getCondition, payload);
      if (res) {
        yield put({
          type: 'save',
          payload: {
            conditionData: res.data,
          },
        });
      } else {
        message.error('查询失败');
      }
    },

    //获取穿梭框产品信息
    *getTranData({ payload, callback }, { call, put }) {
      const res = yield call(api.getProducts1, payload);
      if (res) {
        yield put({
          type: 'save',
          payload: {
            transFormData: res.data,
          },
        });
      } else {
        message.error('查询失败');
      }
    },
    //获取表格扩展数据
    *getRowData({ payload, callback }, { call, put }) {
      const res = yield call(api.getProductGroup, payload);
      if (res) {
        yield put({
          type: 'save',
          payload: {
            rowData: res.data,
          },
        });
        callback(res.data);
      } else {
        message.error('查询失败');
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
